<?php session_start(); ?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>楚瑞涛的博客管理后台-管理员信息</title>
  <link rel="stylesheet" href=<?php echo HOME_CSS.'layui.css' ?> media="all">
  <script type="text/javascript" src=<?php echo HOME_JS.'jquery.min.js' ?> ></script>
  <script src=<?php echo HOME_JS.'layui.js' ?> ></script>
  <script type="text/javascript" src=<?php echo HOME_JS.'md5.js' ?>></script>
  <style>
    .info-title{
      text-align: center;
      font-weight: bold;
      padding-bottom: 20px;
    }
    .layui-form-item>.upload>img{
      width: 200px;
      height:200px;
    }
    .layui-form{
      padding:20px;
    }
    #manimg{
      border: 1px #ccc solid;
      margin-left: 66px;
      width: 200px;
      height: 200px;
    }
  </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">楚瑞涛博客管理后台</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src=<?php echo $_SESSION['m_portrait'] ?>  class="layui-nav-img" alt="头像">
          <input id='m_id' type='hidden' value = <?php echo $_SESSION['m_id'] ?> >
          楚瑞涛
        </a>
        <dl class="layui-nav-child">
          <dd><a href=<?php echo HOME_PATH.'index.php/User/getManAll' ?>>基本资料</a></dd>
          <dd><a href=<?php echo HOME_PATH.'index.php/User/getManagerPass' ?>>修改密码</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a onclick="exit_login()" href="javascript:;">退出</a></li>
    </ul>
  </div>

  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" >
        <li class="layui-nav-item">
          <a class="" href="javascript:;">用户管理
            <span class="layui-nav-more"></span>
          </a>
          <dl class="layui-nav-child">
            <dd><a href=<?php echo HOME_PATH.'index.php/User/getUserAll' ?>>用户管理</a></dd>
            <!-- <dd><a href="javascript:;">权限申请管理</a></dd> -->
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">博客管理
          </a>
          <dl class="layui-nav-child">
            <dd><a href=<?php echo HOME_PATH.'index.php/Blog/getBlogAll' ?> >博客管理</a></dd>
            <dd><a href=<?php echo HOME_PATH.'index.php/Type/getTypeAll' ?> >类别管理</a></dd>
            <dd><a href=<?php echo HOME_PATH.'index.php/Target/getTargetAll' ?>>标签管理</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
            <a href="javascript:;">评论管理</a>
            <dl class="layui-nav-child">
              <dd><a href=<?php echo HOME_PATH.'index.php/Comment/getCommentAll' ?> >评论管理</a></dd>
              <dd><a href=<?php echo HOME_PATH.'index.php/Reply/getReplyAll' ?> >追评管理</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item layui-nav-itemed  ">
            <a href="javascript:;">系统设置</a>
            <dl class="layui-nav-child">
              <dd class="layui-this"><a href=<?php echo HOME_PATH.'index.php/User/getManAll' ?> >个人信息</a></dd>
              <dd><a href=<?php echo HOME_PATH.'index.php/User/getManagerPass' ?> >修改密码</a></dd>
            </dl>
        </li>
      </ul>
    </div>
  </div>
  <!-- setUser -->
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 20px; background-color: #F2F2F2;">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-header">修改个人信息</div>
              <div class="layui-form">
                <div class="layui-form-item">
                  <label class="layui-form-label">用户名：</label>
                  <div class="layui-input-inline  ">
                    <input type="text" id="name" value=<?php echo $name ?> required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">邮箱：</label>
                  <div class="layui-input-inline">
                    <input type="text" id="email" value=<?php echo $email ?> required lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label timelabel">创建时间：</label>
                  <div class="layui-input-inline">
                    <label class="layui-form-label" style="width: 60%;"><span id='name' ><?php echo $create_time ?></span></label>
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label timelabel">上次登陆：</label>
                  <div class="layui-input-inline">
                    <label class="layui-form-label" style="width: 60%;"><span id='email' ><?php echo $last_time ?></span></label>
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">头像：</label>
                  <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="upload">
                      <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                  </div>
                </div>
                <div class="layui-form-item">
                  <img id='manimg' src =<?php echo $portrait ?> alt='头像' />
                </div>
                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn" lay-submit id='submit' >确定修改</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
    </div>
  </div>

<script>
  var oldname = $('#name').val().trim();    //获取姓名
  var oldemail = $('#email').val().trim();    //获取email
  var oldportrait = $('#manimg').attr('src').trim();    //获取图片
  //退出登陆
  function exit_login(){
    layer.alert('确定要退出嘛？',{
      closeBtn: 1    // 是否显示关闭按钮
      ,anim: 1 //动画类型
      ,btn: ['退出','取消'] //按钮
      ,icon: 3    // icon\
      ,title:"退出"
      ,yes:function(){
        $.ajax({
          url:'/blog_system/admin/index.php/Login/exitLogin',
          type:'POST',
          contentType: "application/x-www-form-urlencoded;charset=utf-8",
          success:function(result){
            console.log(result);
            if(result == 1){
              layer.msg('退出登陆成功',{icon: 6, time: 2000});
              $(":root").delay(2000).queue(function(){ window.location.href="/blog_system/admin/index.php"; });   //阿里云搜索跳转
            }else{
              layer.msg('退出登陆失败，请刷新后重试',{icon:5, time: 2000});
            }
          }
        });
      }
    });
  }
  layui.use(['element','form','upload'], function(){
    var element = layui.element;
    var form = layui.form;
    var upload = layui.upload;
    //上传图片
    var uploadInst = upload.render({
      elem: '#upload'   //绑定元素
      ,url: '/blog_system/admin/view/action/upload.php?type=u_tx' //上传接口
      ,size: 2048 // 设置图片大小，单位 KB
      ,done: function(data){
        if(data.code == 200){
          $("#manimg").attr('src',data.file_path);
        }else {
            layer.msg(data.msg,{icon: 5,anim:6, time: 2000}); 
        }
    }
    ,error: function(){
        layer.msg('服务器错误，请稍后重试',{icon: 5,anim:6, time: 2000}); 
    }
    });
  });
  $("#submit").click(function(){
    layer.alert('确定要保存修改内容吗？',{
      closeBtn: 1    // 是否显示关闭按钮
      ,anim: 1 //动画类型
      ,btn: ['退出','取消'] //按钮
      ,icon: 3    // icon\
      ,title:"修改信息"
      ,yes:function(){
        console.log($('#name').val().trim());
        var id = $('#m_id').val();
        var name = $('#name').val().trim();    //获取姓名
        var email = $('#email').val().trim();    //获取email
        var portrait = $('#manimg').attr('src').trim();    //获取图片

        var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;           //用户名正则，4到16位（字母，数字，下划线，减号）
        var ePattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;       //Email正则
        if(name==oldname && oldemail == email && portrait == oldportrait){
          layer.msg('请修改信息后在点击修改按钮！',{icon: 5,anim:6, time: 2000}); 
        }else if(!uPattern.test(name)){
          layer.msg('用户名不能包含特殊字符，且长度是4-16位',{icon: 5,anim:6, time: 2000}); 
        }else if(!ePattern.test(email)){
          layer.msg('请输入正确的E-Mail地址',{icon: 5,anim:6, time: 2000}); 
        }else if(portrait==null || portrait == ''){
          layer.msg('请上传正常的图片',{icon: 5,anim:6, time: 2000}); 
        }else{
          datainfo = {
            name:name,
            email:email,
            portrait:portrait,
            id:id
          };
          $.ajax({                            //发送请求
            url:'/blog_system/admin/index.php/User/editManager',
            type:'POST',
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            data:datainfo,
            success:function(result){
              console.log(result);
              var data = JSON.parse(result);
              if(data.code == 1){
                layer.msg('修改成功',{icon: 6, time: 2000});
                var oldname = name;   
                var oldemail = email;  
                var oldportrait = portrait;   
                $('#name').val(name);
                $('#email').val(email);
              }else{
                layer.msg('修改失败，请刷新后重试',{icon:5, time: 2000});
              }
            }
          });
        }
      }
    });
  });
</script>
  <div class="layui-footer">
    &copy; 河南科技学院-三月小组
  </div>
</div>
</body>
</html>


